import request from '@/utils/request'
import { app } from '@/config'
const rest = {
  list(res: any, params: any, headers = {}) {
    return request({
      url: `/${app}/${res}`,
      method: 'get',
      headers: headers,
      params: params,
    })
  },
  get(res: any, id: any, headers = {}) {
    return request({
      url: `/${app}/${res}/${id}`,
      method: 'get',
      headers: headers,
    })
  },
  create(res: any, data: any, headers = {}) {
    return request({
      url: `/${app}/${res}`,
      method: 'post',
      headers: headers,
      data,
    })
  },
  update(res: any, id: any, data: any, headers = {}) {
    return request({
      url: `/${app}/${res}/${id}`,
      method: 'put',
      headers: headers,
      data,
    })
  },
  delete(res: any, id: any, headers = {}) {
    return request({
      url: `/${app}/${res}/${id}`,
      method: 'delete',
      headers: headers,
    })
  },
  meta(res: any, headers = {}) {
    return request({
      url: `/${app}/${res}`,
      method: 'get',
      params: { _act: 'meta' },
      headers: headers,
    })
  },
  req(url: any, method = 'get', data: any, headers = {}) {
    if (method == 'get') {
      return request({
        url: `/${app}/${url}`,
        method: method,
        headers: headers,
        params: data,
      })
    } else {
      return request({
        url: `/${app}/${url}`,
        method: method,
        headers: headers,
        data,
      })
    }
  },
}

export default rest
